//
//  ShoppingDetailViewController.m
//  成都咖啡
//
//  Created by rimi on 16/3/22.
//  Copyright © 2016年 wenhao. All rights reserved.
//

#import "ShoppingDetailViewController.h"
#import "DefaultsInForCenter.h"
#import "DrawerViewController.h"
#import "ShoppingCenterViewController.h"
#import "TimeCell.h"
#import "ShopTagCell.h"
#import "ShopAddressCell.h"
#import "ShopSpecialCell.h"
#import "ShopDescipeCell.h"
#import "OtherShopCell.h"
#import "ShoppingName.h"

#import "TableHeaderViewController.h"
#import <BmobSDK/Bmob.h>
#import "MapDetailViewController.h"


@interface ShoppingDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *ShopNameLabel;
@property (weak, nonatomic) IBOutlet UIButton *backButton;


@property (strong, nonatomic) NSString *bmobID;
@end
@implementation ShoppingDetailViewController
//这里是控制navi出现与否的关键
-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeInterface];
    

    
    
}

- (void)initializeDataSource{
   
    _ShopNameLabel.text = [ShoppingName shareShoppingName].selectedTitle;
   
    
}
//返回按钮事件
- (IBAction)backButton:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    
   
}

- (void)initializeInterface{
    //隐藏导航栏使用自己的假导航（这里是防止出现阴影）
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    
    //把自定义cell加载到视图

    UINib * timeNibe      = [UINib nibWithNibName:NSStringFromClass([TimeCell class]) bundle:nil];
    [self.tableView registerNib:timeNibe forCellReuseIdentifier:@"TimeCell"];

    UINib * addressNibe   = [UINib nibWithNibName:NSStringFromClass([ShopAddressCell class]) bundle:nil];
    [self.tableView registerNib:addressNibe forCellReuseIdentifier:@"ShopAddressCell"];

    UINib * specialNibe   = [UINib nibWithNibName:NSStringFromClass([ShopSpecialCell class]) bundle:nil];
    [self.tableView registerNib:specialNibe forCellReuseIdentifier:@"ShopSpecialCell"];

    UINib * descipeNibe   = [UINib nibWithNibName:NSStringFromClass([ShopDescipeCell class]) bundle:nil];
    [self.tableView registerNib:descipeNibe forCellReuseIdentifier:@"descipeCell"];

    UINib * otherShopNibe = [UINib nibWithNibName:NSStringFromClass([OtherShopCell class]) bundle:nil];
    [self.tableView registerNib:otherShopNibe forCellReuseIdentifier:@"OtherShopCell"];

    //设置一个图片轮播器到tableview的headerView
    TableHeaderViewController *headerView = [[TableHeaderViewController alloc] init];
    headerView.view.frame  = CGRectMake(0, 0, self.view.frame.size.width, 280);
    
    self.tableView.tableHeaderView = headerView.view;
    
    //    //设置cell高度自适应
    self.tableView.estimatedRowHeight = 66;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    
   

}


#pragma mark - UITableViewDataSource methods
//section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    
    return 6;
}
//row
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
//cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [[UITableViewCell alloc]init];
    
    
    if (indexPath.section == 0) {

        ShopTagCell *cell     = [tableView dequeueReusableCellWithIdentifier:@"ShopTagCell"];
      
        
        return cell;
    }

    if (indexPath.section == 1) {
        TimeCell *cell        = [tableView dequeueReusableCellWithIdentifier:@"TimeCell"];
        return cell;
    }

    if (indexPath.section == 2 ) {
        ShopAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopAddressCell"];
        return cell;
    }

    if (indexPath.section == 3) {
        ShopSpecialCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShopSpecialCell"];
        return cell;
    }

    if (indexPath.section == 4) {
        ShopDescipeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"descipeCell"];
        return cell;
    }

    if (indexPath.section == 5) {
        OtherShopCell *cell   = [tableView dequeueReusableCellWithIdentifier:@"OtherShopCell"];
        return cell;
    }

    
    
    
    
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


- (IBAction)drawerButtonWithPressed:(UIButton *)sender {
    
    DefaultsInForCenter *inforCenter = [DefaultsInForCenter defaultsInforCenter];
    inforCenter.isLeftMenuShow = !inforCenter.isLeftMenuShow;
    //获取屏幕的中心点
    CGFloat cemterX = CGRectGetMinX(self.view.superview.frame);
    if (inforCenter.isLeftMenuShow) {
        [UIView animateWithDuration:0.4 animations:^{
            self.view.superview.frame = CGRectMake(cemterX+150, 64, self.view.bounds.size.width, self.view.bounds.size.height);
        }];
    }else{
        [UIView animateWithDuration:0.4 animations:^{
            self.view.superview.frame = CGRectMake(cemterX-150, 64, self.view.bounds.size.width, self.view.bounds.size.height);
        }];
        

    }
//    NSLog(@"frame = %@", NSStringFromCGRect(self.view.frame));

}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2 && indexPath.row==0) {
        MapDetailViewController * mapVC = [[MapDetailViewController alloc]init];
        [self.navigationController  pushViewController:mapVC animated:YES];
    }
}




















@end
